<?php

// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://demo.thinkadmin.top
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 代码仓库：https://gitee.com/zoujingli/ThinkAdmin
// | github 代码仓库：https://github.com/zoujingli/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\admin\controller;

use library\Controller;
use library\tools\Data;
use think\Db;
// use think\Config;


/**
 * 系统用户管理
 * Class User
 * @package app\admin\controller
 */
class Sync extends Controller
{


    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'SystemUser';

    /**
     * 系统用户管理
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function index()
    {

        return $this->fetch();
    }

    /**
     * 清空数据表
     * @auth         true
     * @throws           hink\Exception
     * @throws           hink\exception\PDOException
     * @HtttpRequest                              get|post
     * @Author       GNLEON
     * @Param
     * @DateTime     2020-10-23T15:15:22+0800
     * @LastTime     2020-10-23T15:15:22+0800
     * @return       [type]                       [description]
     */
    public function cleartable(){

        $dbconf = $this->getconfig('vister_db');
        $table_list = Db::connect($dbconf)->query("show tables");

        if($this->request->isPost()){
            if($this->request->param('table')){
                $table_arr = $this->request->param('table');
                foreach ($table_arr as $key => $value) {
                    # code...
                    if(substr($key, 0,4)=='view'){continue;}

                    $res = Db::connect($dbconf)->query('truncate table '.$key);

                }
            }
        }
            $normal_del_table = [
                'appointment',
                'arrive',
                'company',
                'dept',
                'meeting',
                'question',
                'visiter',
                'visiterlist',
                'user',
                'answer',
                'commodity_orders',
                'scan_log',
                'property_relation',
                'store_member',
                'apply',
            ];
        $this->assign('del_tables_list', $normal_del_table);
        $this->assign('tables_list', $table_list);
        $this->fetch();
    }

}